#include "../Tools/GLHeaders.hpp"
#include "InitGLFunc.hpp"
#include "../Global.hpp"

void InitGL(int width, int height){
  /* white ambient light at half intensity (rgba) */
  GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
  /* super bright, full intensity diffuse light. */
  GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  /* position of light (x, y, z, (position of light)) */
  GLfloat LightPosition[] = { 0.0f, 0.0f, 2.0f, 0.0f };
  
  glEnable(GL_TEXTURE_2D);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Blending
  glEnable(GL_BLEND);
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClearDepth(1.0f);
  glDepthFunc(GL_LEQUAL); // Depth...
  glEnable(GL_DEPTH_TEST);
  glFrontFace(GL_CCW); // Front facing polygons...
  glCullFace(GL_BACK);
  glEnable(GL_CULL_FACE);
	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  glEnable(GL_COLOR_MATERIAL);
  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
  glShadeModel(GL_SMOOTH); 
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,window.min,window.max); 
  glMatrixMode(GL_MODELVIEW);

  glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);  // add lighting (ambient)
  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);  // add lighting (diffuse)
  glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // set light position
  glEnable(GL_LIGHT1); // turn light 1 on
  glEnable(GL_LIGHTING);
  
  GlobalInitGL();
}

